﻿
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public DataRow Convert2ICC_MKRF(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryICC_MKRF(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                case "JLT":
                default:
                    #region
                    dwReturn["ABAID"] = "0";
                    dwReturn["MACHINEID"] = "          ";
                    dwReturn["ABKKDAUFTNR"] = "                    ";
                    dwReturn["ABPART"] = "                    ";
                    dwReturn["ABPVAR"] = "   ";
                    dwReturn["ABPFARBE"] = "          ";
                    dwReturn["JW"] = "  ";
                    dwReturn["ABFMANDANT"] = "00";
                    dwReturn["ABFAUFKRS"] = "  ";
                    dwReturn["ABFAUFLFD"] = "000000";
                    dwReturn["ABFAUFPOS"] = "   ";
                    dwReturn["MKFTP"] = "0000";
                    dwReturn["ABFBASMGE"] = "000000000";
                    dwReturn["ABFME"] = "5";
                    dwReturn["ABFAFOLGE"] = "020";
                    dwReturn["ABFPLANKZ"] = "J";
                    dwReturn["ABFKSTKRS"] = "  ";
                    dwReturn["ABFKST"] = "0400";
                    dwReturn["ABFAGANG"] = "XS             ";
                    dwReturn["ABFMTYP"] = "XS      ";
                    dwReturn["ABFMNRKRS"] = "  ";
                    dwReturn["ABFMLFDNR"] = "0000";
                    dwReturn["ABFMPOS"] = "00";
                    dwReturn["ABFAMASCHZT"] = "600";
                    dwReturn["ABFSOLLMG"] = "500000";
                    dwReturn["ABFSOLLME"] = "5";
                    dwReturn["ABFFIX"] = "N";
                    dwReturn["ABFSTATUS"] = " ";
                    dwReturn["ABFSOLLSTART"] = 20141125;
                    dwReturn["ABFSOLLDAT"] = 20141125;
                    dwReturn["ABFBNRKRS"] = "M ";
                    dwReturn["ABFBLFDNR"] = "0009";
                    dwReturn["ABFBPOS"] = "00";
                    dwReturn["ABFIMNRKRS"] = "  ";
                    dwReturn["ABFIMLFDNR"] = "0000";
                    dwReturn["ABFIMPOS"] = "00";
                    dwReturn["ABFIMG"] = "0";
                    dwReturn["ABFISTARTDAT"] = "0";
                    dwReturn["ABFISTARTZT"] = "0";
                    dwReturn["ABFIENDDAT"] = "0";
                    dwReturn["ABFIENDZT"] = "0";
                    dwReturn["SPCONFIRM"] = "YES     ";
                    dwReturn["MKFPLDATV"] = "20141126";
                    dwReturn["MKFPLTIME"] = "0";
                    dwReturn["MKFSCHICHTV"] = "1";
                    dwReturn["ABFMASCHZE"] = "  ";
                    dwReturn["MKFSORTFD"] = "      ";
                    dwReturn["MKFLFDNR"] = "1";
                    dwReturn["MKFERLKZ"] = " ";
                    dwReturn["MKFERLDAT"] = "0";
                    dwReturn["MKFSME"] = "5";
                    dwReturn["MKFSMG1"] = "0";
                    dwReturn["MKFSMG2"] = "0";
                    dwReturn["MKFSMG3"] = "0";
                    dwReturn["MKFSMG4"] = "0";
                    dwReturn["MKFSMG5"] = "50000";
                    dwReturn["MKFSMG6"] = "0";
                    dwReturn["MKFSMG7"] = "0";
                    dwReturn["MKFSMG8"] = "0";
                    dwReturn["PSTARTTIME"] = "0";
                    dwReturn["PENDTIME"] = "0";
                    dwReturn["ABFMASCHZT"] = "0";
                    dwReturn["ENDATE"] = "20141101";
                    dwReturn["ENDTIME"] = "0";
                    dwReturn["JOBTYPE"] = "S";
                    dwReturn["JP01"] = "1";
                    dwReturn["JP02"] = "CO    ";
                    dwReturn["JP03"] = "   ";
                    dwReturn["JP04"] = "   ";
                    dwReturn["JP05"] = "500";
                    dwReturn["JP06"] = "0";
                    dwReturn["JP07"] = "0";
                    dwReturn["JP08"] = "0";
                    dwReturn["JP09"] = "0";
                    dwReturn["JP10"] = "0";
                    dwReturn["JP11"] = "0";
                    dwReturn["JP12"] = "0";
                    dwReturn["JP13"] = "0";
                    dwReturn["JP14"] = "0";
                    dwReturn["JP15"] = "0";
                    dwReturn["JP16"] = "0";
                    dwReturn["JP17"] = "0";
                    dwReturn["JP18"] = "0";
                    dwReturn["JP19"] = "0";
                    dwReturn["JP20"] = "0";
                    dwReturn["JP21"] = "0";
                    dwReturn["JP22"] = "0";
                    dwReturn["JP23"] = "0";
                    dwReturn["JP24"] = "0";
                    dwReturn["JP25"] = "0";
                    dwReturn["JP26"] = "0";
                    dwReturn["JP27"] = "0";
                    dwReturn["JP28"] = "0";
                    dwReturn["JP29"] = "0";
                    dwReturn["JP30"] = "0";
                    dwReturn["JP31"] = "0";
                    dwReturn["JP32"] = "0";
                    dwReturn["JP33"] = "0";
                    dwReturn["JP34"] = "0";
                    dwReturn["JP35"] = "0";
                    dwReturn["JP36"] = "0";
                    dwReturn["JP37"] = "0";
                    dwReturn["JP38"] = "0";
                    dwReturn["JP39"] = "0";
                    dwReturn["JP41"] = "0";
                    dwReturn["JP42"] = "0";
                    dwReturn["JP43"] = "0";
                    dwReturn["JP44"] = "0";
                    dwReturn["JP45"] = "0";
                    dwReturn["JP46"] = "0";
                    dwReturn["JP47"] = "0";
                    dwReturn["JP48"] = "0";
                    dwReturn["JP49"] = "0";
                    dwReturn["JP50"] = "0";

                    #endregion
                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapICC_MKRF(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_MKRF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryICC_MKRF(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapICC_MKRF(ref dwLocal, dwData);

            if (!flgExist)
            {
                //dwLocal["ABAID"] = GetSeq();
                InsertICC_MKRF(dwLocal, 3);
            }
            UpdateICC_MKRF(dwLocal);
        }
        public void InsertICC_MKRF(DataRow dwData, int option = 1)
        {

            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "INSERT INTO ICC_MKRF (ABAID,JP07,  ABKKDAUFTNR, ABPART, ABPVAR, ABPFARBE, JW, ABFMANDANT, ABFAUFKRS, ABFAUFLFD, ABFAUFPOS, MKFTP, ABFBASMGE,ABFME,ABFAFOLGE, ABFPLANKZ, ABFKSTKRS, ABFKST, ABFAGANG, ABFMTYP, ABFMNRKRS, ABFMLFDNR, ABFMPOS,ABFAMASCHZT, ABFSOLLMG, ABFSOLLME, ABFFIX, ABFSTATUS, ABFSOLLSTART, ABFSOLLDAT, ABFBNRKRS, ABFBLFDNR, ABFBPOS, ABFIMNRKRS, ABFIMLFDNR, ABFIMPOS, ABFIMG, ABFISTARTDAT, ABFISTARTZT, ABFIENDDAT, ABFIENDZT, SPCONFIRM, MKFPLDATV, MKFPLTIME, MKFSCHICHTV, ABFMASCHZE, MKFSORTFD, MKFLFDNR, MKFERLKZ, MKFERLDAT, MKFSME, MKFSMG1, MKFSMG2, MKFSMG3, MKFSMG4, MKFSMG5, MKFSMG6, MKFSMG7, MKFSMG8, PSTARTTIME, PENDTIME, ABFMASCHZT)"
                    + " SELECT SEQ_ICC_ITX.NEXTVAL AS ABAID, 'JobBar', ABKKDAUFTNR,ABPART,ABPVAR,ABPFARBE,'  ' AS JW,ABFMANDANT,ABFAUFKRS,ABFAUFLFD,ABFAUFPOS,'0000' AS MKFTP,ABFBASMGE,ABFME,ABFAFOLGE,ABFPLANKZ,ABFKSTKRS,ABFKST,ABFAGANG, ABFMTYP,ABFMNRKRS,ABFMLFDNR,ABFMPOS,ABFAMASCHZT,ABFSOLLMG,ABFSOLLME,ABFFIX,ABFSTATUS,ABFSOLLSTART,ABFSOLLDAT,NVL(MKFMNRKRS,'  ') AS  ABFBNRKRS,NVL(MKFMLFDNR,'0000') AS ABFBLFDNR,NVL(MKFMPOS,'00') AS ABFBPOS,ABFIMNRKRS,ABFIMLFDNR,ABFIMPOS,ABFIMG,ABFISTARTDAT,ABFISTARTZT,ABFIENDDAT,ABFIENDZT,'        ' AS SPCONFIRM,NVL(MKFPLDATV,0) AS MKFPLDATV,0 as MKFPLTIME,MKFSCHICHTV,ABFMASCHZE,'      ' AS MKFSORTFD,MKFLFDNR, NVL(MKFERLKZ,' '),ABFIENDDAT AS MKFERLDAT,MKFSME,MKFSMG1,MKFSMG2,MKFSMG3,MKFSMG4,MKFSMG5,MKFSMG6,MKFSMG7,MKFSMG8,0 AS PSTARTTIME,0 AS PENDTIME,ABFMASCHZT FROM ABFOLGE F JOIN ABPOS P ON  ABFSTATUS =' 'AND  ABFAGANG=:ABFAGANG AND ABFMANDANT=ABPMANDANT AND ABFAUFKRS=ABPAUFKRS AND ABFAUFLFD=ABPAUFLFD AND ABFAUFPOS=ABPAUFPOS JOIN ABKOPF ON ABKMANDANT=ABPMANDANT AND ABKAUFKRS=ABPAUFKRS AND ABKAUFLFD=ABPAUFLFD LEFT JOIN MKRF S ON MKFMANDANT=ABFMANDANT AND ABFAUFKRS=MKFAUFKRS  AND ABFAUFLFD=MKFAUFLFD AND ABFAUFPOS=MKFAUFPOS AND ABFAFOLGE=MKFAFOLGE WHERE ABFMANDANT=:ABFMANDANT AND ABFKSTKRS=:ABFKSTKRS AND ABFKST=:ABFKST and ABFFIX='J'  AND NOT EXISTS ( SELECT 1 FROM ICC_MKRF X WHERE X.ABFMANDANT=F.ABFMANDANT AND X.ABFAUFKRS=F.ABFAUFKRS AND X.ABFAUFLFD=F.ABFAUFLFD AND X.ABFAUFPOS=F.ABFAUFPOS AND X.ABFAFOLGE=F.ABFAFOLGE AND MKFTP='0000')";
                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("ABFKSTKRS", OracleType.NVarChar).Value = dwData["ABFKSTKRS"].ToString();
                    or1.Parameters.Add("ABFKST", OracleType.NVarChar).Value = dwData["ABFKST"].ToString();
                    or1.Parameters.Add("ABFAGANG", OracleType.NVarChar).Value = dwData["ABFAGANG"].ToString();
                    break;
                case 2:
                    or1.CommandText = "INSERT INTO ICC_MKRF (ABAID,JP07, ABKKDAUFTNR, ABPART, ABPVAR, ABPFARBE, JW, ABFMANDANT, ABFAUFKRS, ABFAUFLFD, ABFAUFPOS, MKFTP, ABFBASMGE,ABFME,ABFAFOLGE, ABFPLANKZ, ABFKSTKRS, ABFKST, ABFAGANG, ABFMTYP, ABFMNRKRS, ABFMLFDNR, ABFMPOS,ABFAMASCHZT, ABFSOLLMG, ABFSOLLME, ABFFIX, ABFSTATUS, ABFSOLLSTART, ABFSOLLDAT, ABFBNRKRS, ABFBLFDNR, ABFBPOS, ABFIMNRKRS, ABFIMLFDNR, ABFIMPOS, ABFIMG, ABFISTARTDAT, ABFISTARTZT, ABFIENDDAT, ABFIENDZT, SPCONFIRM, MKFPLDATV, MKFPLTIME, MKFSCHICHTV, ABFMASCHZE, MKFSORTFD, MKFLFDNR, MKFERLKZ, MKFERLDAT, MKFSME, MKFSMG1, MKFSMG2, MKFSMG3, MKFSMG4, MKFSMG5, MKFSMG6, MKFSMG7, MKFSMG8, PSTARTTIME, PENDTIME, ABFMASCHZT)"
                    + " SELECT SEQ_ICC_ITX.NEXTVAL AS ABAID,'JobBar', ABKKDAUFTNR,ABPART,ABPVAR,ABPFARBE,'  ' AS JW,ABFMANDANT,ABFAUFKRS,ABFAUFLFD,ABFAUFPOS,'0000' AS MKFTP,ABFBASMGE,ABFME,ABFAFOLGE,ABFPLANKZ,ABFKSTKRS,ABFKST,ABFAGANG, ABFMTYP,ABFMNRKRS,ABFMLFDNR,ABFMPOS,ABFAMASCHZT,ABFSOLLMG,ABFSOLLME,ABFFIX,ABFSTATUS,ABFSOLLSTART,ABFSOLLDAT,NVL(MKFMNRKRS,'  ') AS  ABFBNRKRS,NVL(MKFMLFDNR,'0000') AS ABFBLFDNR,NVL(MKFMPOS,'00') AS ABFBPOS,ABFIMNRKRS,ABFIMLFDNR,ABFIMPOS,ABFIMG,ABFISTARTDAT,ABFISTARTZT,ABFIENDDAT,ABFIENDZT,'        ' AS SPCONFIRM,NVL(MKFPLDATV,0) AS MKFPLDATV,0 as MKFPLTIME,MKFSCHICHTV,ABFMASCHZE,'      ' AS MKFSORTFD,MKFLFDNR, NVL(MKFERLKZ,' '),ABFIENDDAT AS MKFERLDAT,MKFSME,MKFSMG1,MKFSMG2,MKFSMG3,MKFSMG4,MKFSMG5,MKFSMG6,MKFSMG7,MKFSMG8,0 AS PSTARTTIME,0 AS PENDTIME,ABFMASCHZT FROM ABFOLGE F JOIN ABPOS P ON ABFSTATUS =' 'AND ABFAGANG=:ABFAGANG AND ABFMANDANT=ABPMANDANT AND ABFAUFKRS=ABPAUFKRS AND ABFAUFLFD=ABPAUFLFD AND ABFAUFPOS=ABPAUFPOS JOIN ABKOPF ON ABKMANDANT=ABPMANDANT AND ABKAUFKRS=ABPAUFKRS AND ABKAUFLFD=ABPAUFLFD LEFT JOIN MKRF S ON MKFMANDANT=ABFMANDANT AND ABFAUFKRS=MKFAUFKRS  AND ABFAUFLFD=MKFAUFLFD AND ABFAUFPOS=MKFAUFPOS AND ABFAFOLGE=MKFAFOLGE  WHERE ABFMANDANT=:ABFMANDANT AND ABFKSTKRS=:ABFKSTKRS AND ABFKST=:ABFKST  AND NOT EXISTS ( SELECT 1 FROM ICC_MKRF X WHERE X.ABFMANDANT=F.ABFMANDANT AND X.ABFAUFKRS=F.ABFAUFKRS AND X.ABFAUFLFD=F.ABFAUFLFD AND X.ABFAUFPOS=F.ABFAUFPOS AND X.ABFAFOLGE=F.ABFAFOLGE  AND MKFTP='0000')";
                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("ABFKSTKRS", OracleType.NVarChar).Value = dwData["ABFKSTKRS"].ToString();
                    or1.Parameters.Add("ABFKST", OracleType.NVarChar).Value = dwData["ABFKST"].ToString();
                    or1.Parameters.Add("ABFAGANG", OracleType.NVarChar).Value = dwData["ABFAGANG"].ToString();
                    break;
                case 3:
                    or1.CommandText = "INSERT INTO ICC_MKRF (ABAID)"
                    + " VALUES( :ABAID)";
                    or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                    break;
                case 4://将所有的生产单做为任务插入
                    or1.CommandText = "INSERT INTO ICC_MKRF (ABAID,JOBTYPE,JP06,JP07,ABKKDAUFTNR, ABPART, ABPVAR, ABPFARBE, JW, ABFMANDANT, ABFAUFKRS, ABFAUFLFD, ABFAUFPOS, MKFTP, ABFBASMGE,ABFME,ABFAFOLGE, ABFPLANKZ, ABFKSTKRS, ABFKST, ABFAGANG, ABFMTYP, ABFMNRKRS, ABFMLFDNR, ABFMPOS,ABFAMASCHZT, ABFSOLLMG, ABFSOLLME, ABFFIX, ABFSTATUS, ABFSOLLSTART, ABFSOLLDAT, ABFBNRKRS, ABFBLFDNR, ABFBPOS, ABFIMNRKRS, ABFIMLFDNR, ABFIMPOS, ABFIMG, ABFISTARTDAT, ABFISTARTZT, ABFIENDDAT, ABFIENDZT, SPCONFIRM, MKFPLDATV, MKFPLTIME, MKFSCHICHTV, ABFMASCHZE, MKFSORTFD, MKFLFDNR, MKFERLKZ, MKFERLDAT, MKFSME, MKFSMG1, MKFSMG2, MKFSMG3, MKFSMG4, MKFSMG5, MKFSMG6, MKFSMG7, MKFSMG8, PSTARTTIME, PENDTIME, ABFMASCHZT)"
                    + " SELECT SEQ_ICC_ITX.NEXTVAL AS ABAID, 'W' AS JOBTYPE,  ABPPOSTYP, ABPAUFART, ABKKDAUFTNR,       ABPART,       ABPVAR,       ABPFARBE,       '  ' AS JW,       ABFMANDANT,       ABFAUFKRS,       ABFAUFLFD,       ABFAUFPOS,       '0000' AS MKFTP,       ABFBASMGE,       ABFME,       '000' AS ABFAFOLGE,       ABFPLANKZ,       '99' AS ABFKSTKRS,       '9999' AS ABFKST,       '999            ' AS ABFAGANG,      '99999999' AS ABFMTYP,       '99' AS ABFMNRKRS,       '9999' AS ABFMLFDNR,       ABFMPOS,       ABFAMASCHZT,       ABFSOLLMG,       ABFSOLLME,       'J' AS ABFFIX,       ABFSTATUS,       ABFSOLLSTART,       ABFSOLLDAT,       NVL(MKFMNRKRS, '  ') AS ABFBNRKRS,       NVL(MKFMLFDNR, '0000') AS ABFBLFDNR,       NVL(MKFMPOS, '00') AS ABFBPOS,       ABFIMNRKRS,       ABFIMLFDNR,       ABFIMPOS,       ABFIMG,       ABFISTARTDAT,       ABFISTARTZT,       ABFIENDDAT,       ABFIENDZT,       '        ' AS SPCONFIRM,       NVL(ABPSTARTDAT, 0) AS MKFPLDATV,       0 as MKFPLTIME,       MKFSCHICHTV,       ABFMASCHZE,       '      ' AS MKFSORTFD,       MKFLFDNR,       ABPERLKZ AS MKFERLKZ,       ABPERLDAT AS MKFERLDAT,       MKFSME,      ABPSOLLMENGE1 AS MKFSMG1,      ABPSOLLMENGE2 AS   MKFSMG2,      ABPSOLLMENGE3 AS   MKFSMG3,       ABPSOLLMENGE4 AS  MKFSMG4,      ABPSOLLMENGE5 AS   MKFSMG5,      ABPSOLLMENGE6 AS   MKFSMG6,     ABPSOLLMENGE7 AS    MKFSMG7,      ABPSOLLMENGE8 AS   MKFSMG8,       ABPSTARTDAT AS PSTARTTIME,       ABPENDDAT AS PENDTIME,       ABFMASCHZT  FROM ABFOLGE F  JOIN ABPOS P    ON ABFAFOLGE = '010'   AND ABFMANDANT = ABPMANDANT   AND ABFAUFKRS = ABPAUFKRS   AND ABFAUFLFD = ABPAUFLFD   AND ABFAUFPOS = ABPAUFPOS  JOIN ABKOPF    ON ABKMANDANT = ABPMANDANT   AND ABKAUFKRS = ABPAUFKRS   AND ABKAUFLFD = ABPAUFLFD  LEFT JOIN MKRF S    ON MKFMANDANT = ABFMANDANT   AND ABFAUFKRS = MKFAUFKRS   AND ABFAUFLFD = MKFAUFLFD   AND ABFAUFPOS = MKFAUFPOS   AND ABFAFOLGE = MKFAFOLGE WHERE ABFMANDANT = '00'   AND NOT EXISTS (SELECT 1          FROM ICC_MKRF X         WHERE X.ABFMANDANT = F.ABFMANDANT           AND X.ABFAUFKRS = F.ABFAUFKRS           AND X.ABFAUFLFD = F.ABFAUFLFD           AND X.ABFAUFPOS = F.ABFAUFPOS           AND X.ABFAFOLGE = '000'           AND MKFTP = '0000')";
                    break;
                case 5://将所有的销售单做为任务插入
                    or1.CommandText = "INSERT INTO ICC_MKRF (ABAID,JOBTYPE,JP06,JP07,ABKKDAUFTNR, ABPART, ABPVAR, ABPFARBE, ABFMANDANT, ABFAUFKRS, ABFAUFLFD, ABFAUFPOS, MKFTP,ABFBASMGE,ABFAFOLGE, ABFKSTKRS, ABFKST, ABFAGANG, ABFMTYP, ABFMNRKRS, ABFMLFDNR, ABFMPOS, MKFPLDATV,ENDATE,ABFSOLLSTART, ABFSOLLDAT,ABFBNRKRS, ABFBLFDNR, ABFBPOS, ABFIMNRKRS, ABFIMLFDNR, ABFIMPOS, MKFERLKZ, MKFERLDAT, PSTARTTIME, PENDTIME)"
                        + " SELECT SEQ_ICC_ITX.NEXTVAL AS ABAID, 'W' AS JOBTYPE, VKPPOSTYP,'VK' AS ABPAUFART, VKKAUFKRS||'-'||SUBSTR(VKKAUFLFD,-4) AS  ABKKDAUFTNR, VAFPART AS ABPART, VAFPVAR AS ABPVAR, VAFFFARBE AS ABPFARBE,VKPMANDANT AS ABFMANDANT,VKPAUFKRS AS ABFAUFKRS, VKPAUFLFD AS ABFAUFLFD, VKPAUFPOS AS ABFAUFPOS,'0000' AS MKFTP,ROUND(VKPMENGE1*VKPMEEHFKT*0.001*0.001*0.01*1000) AS ABFBASMGE,'000' AS ABFAFOLGE,'99' AS ABFKSTKRS,'9999' AS ABFKST,'999            ' AS ABFAGANG, '99999999' AS ABFMTYP,'99' AS ABFMNRKRS,'9999' AS ABFMLFDNR, '00' AS ABFMPOS,  VKPNEUDAT AS MKFPLDATV, VKPLIEFTERM AS ENDDATE,   VKPNEUDAT AS   ABFSOLLSTART,  VKPNEUDAT AS  ABFSOLLDAT,'99'  AS ABFBNRKRS, '9999' AS ABFBLFDNR, '00' AS ABFBPOS,  '99'  AS ABFIMNRKRS, '9999' AS ABFIMLFDNR,  '00' AS ABFIMPOS,VKPERL AS MKFERLKZ,VKPERLDAT AS MKFERLDAT, VKPNEUDAT AS PSTARTTIME,VKPERLDAT AS PENDTIME FROM VKPOS P JOIN  VAFARBEN M ON  VKPSA = '  ' AND VKPKOLL=VAFKOLL AND VKPART=VAFART AND VKPFARBE=VAFFARBE  JOIN VKKOPF  ON  VKKSA='  ' AND VKKMANDANT = VKPMANDANT AND VKKAUFKRS = VKPAUFKRS AND VKKAUFLFD = VKPAUFLFD  WHERE  VKPSA='  ' AND VKPMANDANT = '00'   AND NOT EXISTS (SELECT 1  FROM ICC_MKRF X   WHERE X.ABFMANDANT = P.VKPMANDANT AND X.ABFAUFKRS = P.VKPAUFKRS  AND X.ABFAUFLFD = P.VKPAUFLFD  AND X.ABFAUFPOS = P.VKPAUFPOS AND X.ABFAFOLGE = '000'    AND MKFTP = '0000') ";
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_MKRF(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_MKRF"
                        + " WHERE rownum<2";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_MKRF"
                        + " WHERE ABAID=:ABAID";
                    or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                    break;
                case 2:
                    or1.CommandText = "  SELECT  Y.JWS,Y.GUSAGE,NVL(Y.CR,'108') AS CR,NVL(Y.CG,'108') AS CG,NVL(Y.CB,'108') AS CB,NVL(Y.RGB,'0') AS RGB,NVL(Y.CGROUP,'1') AS CGROUP ,M.*,P.* FROM  ICC_MKRF M LEFT JOIN ICC_JWYARN Y ON ABPART=Y.GART AND ABPVAR=Y.GVAR AND ABPFARBE=GFARBE LEFT JOIN ICC_PVKPOS P ON P.VAFPART=WART AND VAFFFARBE=WFARBE AND VKPEND=0 "
                        + " WHERE ABFMANDANT=:ABFMANDANT AND ABFKSTKRS=:ABFKSTKRS AND ABFKST=:ABFKST";
                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("ABFKSTKRS", OracleType.NVarChar).Value = dwData["ABFKSTKRS"].ToString();
                    or1.Parameters.Add("ABFKST", OracleType.NVarChar).Value = dwData["ABFKST"].ToString();
                    break;
                case 3:
                    or1.CommandText = "SELECT DISTINCT NVL(Y.CR,'108') AS CR,NVL(Y.CG,'108') AS CG,NVL(Y.CB,'108') AS CB,NVL(Y.RGB,'0') AS RGB,NVL(Y.CGROUP,'1') AS CGROUP,M.* FROM  ICC_MKRF M LEFT JOIN ICC_JWYARN Y ON ABPART=Y.GART AND ABPVAR=Y.GVAR AND ABPFARBE=GFARBE LEFT JOIN ICC_PVKPOS P ON P.VAFPART=WART AND VAFFFARBE=WFARBE AND VKPEND=0 "
                        + " WHERE ABFMANDANT=:ABFMANDANT AND ABFKSTKRS=:ABFKSTKRS AND ABFKST=:ABFKST";
                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("ABFKSTKRS", OracleType.NVarChar).Value = dwData["ABFKSTKRS"].ToString();
                    or1.Parameters.Add("ABFKST", OracleType.NVarChar).Value = dwData["ABFKST"].ToString();
                    break;
                case 4:
                    or1.CommandText = "SELECT M.*, 108 AS CR, 108 AS CG,108 AS CB,255 AS RGB,1 AS CGROUP FROM ICC_MKRF M "
                        + " WHERE JP49>0";
                    break;
                case 5:
                    or1.CommandText = "SELECT M.* FROM  ICC_MKRF M "
                        + " WHERE ABFMANDANT=:ABFMANDANT AND ABFAUFKRS=:ABFAUFKRS AND ABFAUFLFD=:ABFAUFLFD";
                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("ABFAUFKRS", OracleType.NVarChar).Value = dwData["ABFAUFKRS"].ToString();
                    or1.Parameters.Add("ABFAUFLFD", OracleType.NVarChar).Value = dwData["ABFAUFLFD"].ToString();
                    break;
                case 6:
                    or1.CommandText = "SELECT DISTINCT NVL(Y.CR,'108') AS CR,NVL(Y.CG,'108') AS CG,NVL(Y.CB,'108') AS CB,NVL(Y.RGB,'0') AS RGB,NVL(Y.CGROUP,'1') AS CGROUP,M.* FROM  ICC_MKRF M LEFT JOIN ICC_JWYARN Y ON ABPART=Y.GART AND ABPVAR=Y.GVAR AND ABPFARBE=GFARBE  "
                        + " WHERE ABFKST='9999' AND ABFMANDANT=:ABFMANDANT AND ABFAUFKRS=:ABFAUFKRS AND ABFAUFLFD=:ABFAUFLFD AND ABFAUFPOS=:ABFAUFPOS";
                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("ABFAUFKRS", OracleType.NVarChar).Value = dwData["ABFAUFKRS"].ToString();
                    or1.Parameters.Add("ABFAUFLFD", OracleType.NVarChar).Value = dwData["ABFAUFLFD"].ToString();
                    or1.Parameters.Add("ABFAUFPOS", OracleType.NVarChar).Value = dwData["ABFAUFPOS"].ToString();
                    break;
                case 7:
                    or1.CommandText = "SELECT DISTINCT NVL(Y.CR,'108') AS CR,NVL(Y.CG,'108') AS CG,NVL(Y.CB,'108') AS CB,NVL(Y.RGB,'0') AS RGB,NVL(Y.CGROUP,'1') AS CGROUP,M.* "
                    +" FROM  ICC_MKRF M LEFT JOIN ICC_JWYARN Y ON ABPART=Y.GART AND ABPVAR=Y.GVAR AND ABPFARBE=GFARBE "
                    + " JOIN ICC_QUERYTB X ON m.ABFAUFKRS=X.ABPAUFKRS AND M.ABFAUFLFD =X.ABPAUFLFD AND X.ABPAUFPOS=M.ABFAUFPOS "
                    + " WHERE M.ABFKST='9999' AND RTRIM(X.EXART)=:EXART";
                    or1.Parameters.Add("EXART", OracleType.NVarChar).Value = dwData["EXART"].ToString().Trim(); ;
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_MKRF";
            Return = Result;
            return Return;
        }
        public void UpdateICC_MKRF(DataRow dwData, int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region
                    or1.CommandText = "UPDATE ICC_MKRF SET "
                    + "MACHINEID=:MACHINEID,"
                    + "ABKKDAUFTNR=:ABKKDAUFTNR,"
                    + "ABPART=:ABPART,"
                    + "ABPVAR=:ABPVAR,"
                    + "ABPFARBE=:ABPFARBE,"
                    + "JW=:JW,"
                    + "ABFMANDANT=:ABFMANDANT,"
                    + "ABFAUFKRS=:ABFAUFKRS,"
                    + "ABFAUFLFD=:ABFAUFLFD,"
                    + "ABFAUFPOS=:ABFAUFPOS,"
                    + "MKFTP=:MKFTP,"
                    + "ABFBASMGE=:ABFBASMGE,"
                    + "ABFME=:ABFME,"
                    + "ABFAFOLGE=:ABFAFOLGE,"
                    + "ABFPLANKZ=:ABFPLANKZ,"
                    + "ABFKSTKRS=:ABFKSTKRS,"
                    + "ABFKST=:ABFKST,"
                    + "ABFAGANG=:ABFAGANG,"
                    + "ABFMTYP=:ABFMTYP,"
                    + "ABFMNRKRS=:ABFMNRKRS,"
                    + "ABFMLFDNR=:ABFMLFDNR,"
                    + "ABFMPOS=:ABFMPOS,"
                    + "ABFAMASCHZT=:ABFAMASCHZT,"
                    + "ABFSOLLMG=:ABFSOLLMG,"
                    + "ABFSOLLME=:ABFSOLLME,"
                    + "ABFFIX=:ABFFIX,"
                    + "ABFSTATUS=:ABFSTATUS,"
                    + "ABFSOLLSTART=:ABFSOLLSTART,"
                    + "ABFSOLLDAT=:ABFSOLLDAT,"
                    + "ABFBNRKRS=:ABFBNRKRS,"
                    + "ABFBLFDNR=:ABFBLFDNR,"
                    + "ABFBPOS=:ABFBPOS,"
                    + "ABFIMNRKRS=:ABFIMNRKRS,"
                    + "ABFIMLFDNR=:ABFIMLFDNR,"
                    + "ABFIMPOS=:ABFIMPOS,"
                    + "ABFIMG=:ABFIMG,"
                    + "ABFISTARTDAT=:ABFISTARTDAT,"
                    + "ABFISTARTZT=:ABFISTARTZT,"
                    + "ABFIENDDAT=:ABFIENDDAT,"
                    + "ABFIENDZT=:ABFIENDZT,"
                    + "SPCONFIRM=:SPCONFIRM,"
                    + "MKFPLDATV=:MKFPLDATV,"
                    + "MKFPLTIME=:MKFPLTIME,"
                    + "MKFSCHICHTV=:MKFSCHICHTV,"
                    + "ABFMASCHZE=:ABFMASCHZE,"
                    + "MKFSORTFD=:MKFSORTFD,"
                    + "MKFLFDNR=:MKFLFDNR,"
                    + "MKFERLKZ=:MKFERLKZ,"
                    + "MKFERLDAT=:MKFERLDAT,"
                    + "MKFSME=:MKFSME,"
                    + "MKFSMG1=:MKFSMG1,"
                    + "MKFSMG2=:MKFSMG2,"
                    + "MKFSMG3=:MKFSMG3,"
                    + "MKFSMG4=:MKFSMG4,"
                    + "MKFSMG5=:MKFSMG5,"
                    + "MKFSMG6=:MKFSMG6,"
                    + "MKFSMG7=:MKFSMG7,"
                    + "MKFSMG8=:MKFSMG8,"
                    + "PSTARTTIME=:PSTARTTIME,"
                    + "PENDTIME=:PENDTIME,"
                    + "ABFMASCHZT=:ABFMASCHZT,"
                    + "ENDATE=:ENDATE,"
                    + "ENDTIME=:ENDTIME,"
                    + "JOBTYPE=:JOBTYPE,"
                    + "JP01=:JP01,"
                    + "JP02=:JP02,"
                    + "JP03=:JP03,"
                    + "JP04=:JP04,"
                    + "JP05=:JP05,"
                    + "JP06=:JP06,"
                    + "JP07=:JP07,"
                    + "JP08=:JP08,"
                    + "JP09=:JP09,"
                    + "JP10=:JP10,"
                    + "JP11=:JP11,"
                    + "JP12=:JP12,"
                    + "JP13=:JP13,"
                    + "JP14=:JP14,"
                    + "JP15=:JP15,"
                    + "JP16=:JP16,"
                    + "JP17=:JP17,"
                    + "JP18=:JP18,"
                    + "JP19=:JP19,"
                    + "JP20=:JP20,"
                    + "JP21=:JP21,"
                    + "JP22=:JP22,"
                    + "JP23=:JP23,"
                    + "JP24=:JP24,"
                    + "JP25=:JP25,"
                    + "JP26=:JP26,"
                    + "JP27=:JP27,"
                    + "JP28=:JP28,"
                    + "JP29=:JP29,"
                    + "JP30=:JP30,"
                    + "JP31=:JP31,"
                    + "JP32=:JP32,"
                    + "JP33=:JP33,"
                    + "JP34=:JP34,"
                    + "JP35=:JP35,"
                    + "JP36=:JP36,"
                    + "JP37=:JP37,"
                    + "JP38=:JP38,"
                    + "JP39=:JP39,"
                    + "JP41=:JP41,"
                    + "JP42=:JP42,"
                    + "JP43=:JP43,"
                    + "JP44=:JP44,"
                    + "JP45=:JP45,"
                    + "JP46=:JP46,"
                    + "JP47=:JP47,"
                    + "JP48=:JP48,"
                    + "JP49=:JP49,"
                    + "JP50=:JP50"
                    + " WHERE ABAID=:ABAID";
                    or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                    or1.Parameters.Add("MACHINEID", OracleType.NVarChar).Value = dwData["MACHINEID"].ToString();
                    or1.Parameters.Add("ABKKDAUFTNR", OracleType.NVarChar).Value = dwData["ABKKDAUFTNR"].ToString();
                    or1.Parameters.Add("ABPART", OracleType.NVarChar).Value = dwData["ABPART"].ToString();
                    or1.Parameters.Add("ABPVAR", OracleType.NVarChar).Value = dwData["ABPVAR"].ToString();
                    or1.Parameters.Add("ABPFARBE", OracleType.NVarChar).Value = dwData["ABPFARBE"].ToString();
                    or1.Parameters.Add("JW", OracleType.NVarChar).Value = dwData["JW"].ToString();
                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("ABFAUFKRS", OracleType.NVarChar).Value = dwData["ABFAUFKRS"].ToString();
                    or1.Parameters.Add("ABFAUFLFD", OracleType.NVarChar).Value = dwData["ABFAUFLFD"].ToString();
                    or1.Parameters.Add("ABFAUFPOS", OracleType.NVarChar).Value = dwData["ABFAUFPOS"].ToString();
                    or1.Parameters.Add("MKFTP", OracleType.NVarChar).Value = dwData["MKFTP"].ToString();
                    or1.Parameters.Add("ABFBASMGE", OracleType.NVarChar).Value = dwData["ABFBASMGE"].ToString();
                    or1.Parameters.Add("ABFME", OracleType.NVarChar).Value = dwData["ABFME"].ToString();
                    or1.Parameters.Add("ABFAFOLGE", OracleType.NVarChar).Value = dwData["ABFAFOLGE"].ToString();
                    or1.Parameters.Add("ABFPLANKZ", OracleType.NVarChar).Value = dwData["ABFPLANKZ"].ToString();
                    or1.Parameters.Add("ABFKSTKRS", OracleType.NVarChar).Value = dwData["ABFKSTKRS"].ToString();
                    or1.Parameters.Add("ABFKST", OracleType.NVarChar).Value = dwData["ABFKST"].ToString();
                    or1.Parameters.Add("ABFAGANG", OracleType.NVarChar).Value = dwData["ABFAGANG"].ToString();
                    or1.Parameters.Add("ABFMTYP", OracleType.NVarChar).Value = dwData["ABFMTYP"].ToString();
                    or1.Parameters.Add("ABFMNRKRS", OracleType.NVarChar).Value = dwData["ABFMNRKRS"].ToString();
                    or1.Parameters.Add("ABFMLFDNR", OracleType.NVarChar).Value = dwData["ABFMLFDNR"].ToString();
                    or1.Parameters.Add("ABFMPOS", OracleType.NVarChar).Value = dwData["ABFMPOS"].ToString();
                    or1.Parameters.Add("ABFAMASCHZT", OracleType.NVarChar).Value = dwData["ABFAMASCHZT"].ToString();
                    or1.Parameters.Add("ABFSOLLMG", OracleType.NVarChar).Value = dwData["ABFSOLLMG"].ToString();
                    or1.Parameters.Add("ABFSOLLME", OracleType.NVarChar).Value = dwData["ABFSOLLME"].ToString();
                    or1.Parameters.Add("ABFFIX", OracleType.NVarChar).Value = dwData["ABFFIX"].ToString();
                    or1.Parameters.Add("ABFSTATUS", OracleType.NVarChar).Value = dwData["ABFSTATUS"].ToString();
                    or1.Parameters.Add("ABFSOLLSTART", OracleType.NVarChar).Value = dwData["ABFSOLLSTART"].ToString();
                    or1.Parameters.Add("ABFSOLLDAT", OracleType.NVarChar).Value = dwData["ABFSOLLDAT"].ToString();
                    or1.Parameters.Add("ABFBNRKRS", OracleType.NVarChar).Value = dwData["ABFBNRKRS"].ToString();
                    or1.Parameters.Add("ABFBLFDNR", OracleType.NVarChar).Value = dwData["ABFBLFDNR"].ToString();
                    or1.Parameters.Add("ABFBPOS", OracleType.NVarChar).Value = dwData["ABFBPOS"].ToString();
                    or1.Parameters.Add("ABFIMNRKRS", OracleType.NVarChar).Value = dwData["ABFIMNRKRS"].ToString();
                    or1.Parameters.Add("ABFIMLFDNR", OracleType.NVarChar).Value = dwData["ABFIMLFDNR"].ToString();
                    or1.Parameters.Add("ABFIMPOS", OracleType.NVarChar).Value = dwData["ABFIMPOS"].ToString();
                    or1.Parameters.Add("ABFIMG", OracleType.NVarChar).Value = dwData["ABFIMG"].ToString();
                    or1.Parameters.Add("ABFISTARTDAT", OracleType.NVarChar).Value = dwData["ABFISTARTDAT"].ToString();
                    or1.Parameters.Add("ABFISTARTZT", OracleType.NVarChar).Value = dwData["ABFISTARTZT"].ToString();
                    or1.Parameters.Add("ABFIENDDAT", OracleType.NVarChar).Value = dwData["ABFIENDDAT"].ToString();
                    or1.Parameters.Add("ABFIENDZT", OracleType.NVarChar).Value = dwData["ABFIENDZT"].ToString();
                    or1.Parameters.Add("SPCONFIRM", OracleType.NVarChar).Value = dwData["SPCONFIRM"].ToString();
                    or1.Parameters.Add("MKFPLDATV", OracleType.NVarChar).Value = dwData["MKFPLDATV"].ToString();
                    or1.Parameters.Add("MKFPLTIME", OracleType.NVarChar).Value = dwData["MKFPLTIME"].ToString();
                    or1.Parameters.Add("MKFSCHICHTV", OracleType.NVarChar).Value = dwData["MKFSCHICHTV"].ToString();
                    or1.Parameters.Add("ABFMASCHZE", OracleType.NVarChar).Value = dwData["ABFMASCHZE"].ToString();
                    or1.Parameters.Add("MKFSORTFD", OracleType.NVarChar).Value = dwData["MKFSORTFD"].ToString();
                    or1.Parameters.Add("MKFLFDNR", OracleType.NVarChar).Value = dwData["MKFLFDNR"].ToString();
                    or1.Parameters.Add("MKFERLKZ", OracleType.NVarChar).Value = dwData["MKFERLKZ"].ToString();
                    or1.Parameters.Add("MKFERLDAT", OracleType.NVarChar).Value = dwData["MKFERLDAT"].ToString();
                    or1.Parameters.Add("MKFSME", OracleType.NVarChar).Value = dwData["MKFSME"].ToString();
                    or1.Parameters.Add("MKFSMG1", OracleType.NVarChar).Value = dwData["MKFSMG1"].ToString();
                    or1.Parameters.Add("MKFSMG2", OracleType.NVarChar).Value = dwData["MKFSMG2"].ToString();
                    or1.Parameters.Add("MKFSMG3", OracleType.NVarChar).Value = dwData["MKFSMG3"].ToString();
                    or1.Parameters.Add("MKFSMG4", OracleType.NVarChar).Value = dwData["MKFSMG4"].ToString();
                    or1.Parameters.Add("MKFSMG5", OracleType.NVarChar).Value = dwData["MKFSMG5"].ToString();
                    or1.Parameters.Add("MKFSMG6", OracleType.NVarChar).Value = dwData["MKFSMG6"].ToString();
                    or1.Parameters.Add("MKFSMG7", OracleType.NVarChar).Value = dwData["MKFSMG7"].ToString();
                    or1.Parameters.Add("MKFSMG8", OracleType.NVarChar).Value = dwData["MKFSMG8"].ToString();
                    or1.Parameters.Add("PSTARTTIME", OracleType.NVarChar).Value = dwData["PSTARTTIME"].ToString();
                    or1.Parameters.Add("PENDTIME", OracleType.NVarChar).Value = dwData["PENDTIME"].ToString();
                    or1.Parameters.Add("ABFMASCHZT", OracleType.NVarChar).Value = dwData["ABFMASCHZT"].ToString();
                    or1.Parameters.Add("ENDATE", OracleType.NVarChar).Value = dwData["ENDATE"].ToString();
                    or1.Parameters.Add("ENDTIME", OracleType.NVarChar).Value = dwData["ENDTIME"].ToString();
                    or1.Parameters.Add("JOBTYPE", OracleType.NVarChar).Value = dwData["JOBTYPE"].ToString();
                    or1.Parameters.Add("JP01", OracleType.NVarChar).Value = dwData["JP01"].ToString();
                    or1.Parameters.Add("JP02", OracleType.NVarChar).Value = dwData["JP02"].ToString();
                    or1.Parameters.Add("JP03", OracleType.NVarChar).Value = dwData["JP03"].ToString();
                    or1.Parameters.Add("JP04", OracleType.NVarChar).Value = dwData["JP04"].ToString();
                    or1.Parameters.Add("JP05", OracleType.NVarChar).Value = dwData["JP05"].ToString();
                    or1.Parameters.Add("JP06", OracleType.NVarChar).Value = dwData["JP06"].ToString();
                    or1.Parameters.Add("JP07", OracleType.NVarChar).Value = dwData["JP07"].ToString();
                    or1.Parameters.Add("JP08", OracleType.NVarChar).Value = dwData["JP08"].ToString();
                    or1.Parameters.Add("JP09", OracleType.NVarChar).Value = dwData["JP09"].ToString();
                    or1.Parameters.Add("JP10", OracleType.NVarChar).Value = dwData["JP10"].ToString();
                    or1.Parameters.Add("JP11", OracleType.NVarChar).Value = dwData["JP11"].ToString();
                    or1.Parameters.Add("JP12", OracleType.NVarChar).Value = dwData["JP12"].ToString();
                    or1.Parameters.Add("JP13", OracleType.NVarChar).Value = dwData["JP13"].ToString();
                    or1.Parameters.Add("JP14", OracleType.NVarChar).Value = dwData["JP14"].ToString();
                    or1.Parameters.Add("JP15", OracleType.NVarChar).Value = dwData["JP15"].ToString();
                    or1.Parameters.Add("JP16", OracleType.NVarChar).Value = dwData["JP16"].ToString();
                    or1.Parameters.Add("JP17", OracleType.NVarChar).Value = dwData["JP17"].ToString();
                    or1.Parameters.Add("JP18", OracleType.NVarChar).Value = dwData["JP18"].ToString();
                    or1.Parameters.Add("JP19", OracleType.NVarChar).Value = dwData["JP19"].ToString();
                    or1.Parameters.Add("JP20", OracleType.NVarChar).Value = dwData["JP20"].ToString();
                    or1.Parameters.Add("JP21", OracleType.NVarChar).Value = dwData["JP21"].ToString();
                    or1.Parameters.Add("JP22", OracleType.NVarChar).Value = dwData["JP22"].ToString();
                    or1.Parameters.Add("JP23", OracleType.NVarChar).Value = dwData["JP23"].ToString();
                    or1.Parameters.Add("JP24", OracleType.NVarChar).Value = dwData["JP24"].ToString();
                    or1.Parameters.Add("JP25", OracleType.NVarChar).Value = dwData["JP25"].ToString();
                    or1.Parameters.Add("JP26", OracleType.NVarChar).Value = dwData["JP26"].ToString();
                    or1.Parameters.Add("JP27", OracleType.NVarChar).Value = dwData["JP27"].ToString();
                    or1.Parameters.Add("JP28", OracleType.NVarChar).Value = dwData["JP28"].ToString();
                    or1.Parameters.Add("JP29", OracleType.NVarChar).Value = dwData["JP29"].ToString();
                    or1.Parameters.Add("JP30", OracleType.NVarChar).Value = dwData["JP30"].ToString();
                    or1.Parameters.Add("JP31", OracleType.NVarChar).Value = dwData["JP31"].ToString();
                    or1.Parameters.Add("JP32", OracleType.NVarChar).Value = dwData["JP32"].ToString();
                    or1.Parameters.Add("JP33", OracleType.NVarChar).Value = dwData["JP33"].ToString();
                    or1.Parameters.Add("JP34", OracleType.NVarChar).Value = dwData["JP34"].ToString();
                    or1.Parameters.Add("JP35", OracleType.NVarChar).Value = dwData["JP35"].ToString();
                    or1.Parameters.Add("JP36", OracleType.NVarChar).Value = dwData["JP36"].ToString();
                    or1.Parameters.Add("JP37", OracleType.NVarChar).Value = dwData["JP37"].ToString();
                    or1.Parameters.Add("JP38", OracleType.NVarChar).Value = dwData["JP38"].ToString();
                    or1.Parameters.Add("JP39", OracleType.NVarChar).Value = dwData["JP39"].ToString();
                    or1.Parameters.Add("JP41", OracleType.NVarChar).Value = dwData["JP41"].ToString();
                    or1.Parameters.Add("JP42", OracleType.NVarChar).Value = dwData["JP42"].ToString();
                    or1.Parameters.Add("JP43", OracleType.NVarChar).Value = dwData["JP43"].ToString();
                    or1.Parameters.Add("JP44", OracleType.NVarChar).Value = dwData["JP44"].ToString();
                    or1.Parameters.Add("JP45", OracleType.NVarChar).Value = dwData["JP45"].ToString();
                    or1.Parameters.Add("JP46", OracleType.NVarChar).Value = dwData["JP46"].ToString();
                    or1.Parameters.Add("JP47", OracleType.NVarChar).Value = dwData["JP47"].ToString();
                    or1.Parameters.Add("JP48", OracleType.NVarChar).Value = dwData["JP48"].ToString();
                    or1.Parameters.Add("JP49", OracleType.NVarChar).Value = dwData["JP49"].ToString();
                    or1.Parameters.Add("JP50", OracleType.NVarChar).Value = dwData["JP50"].ToString();
                    #endregion
                    break;
                case 2:
                    or1.CommandText = "UPDATE  ICC_MKRF SET JW='W ' WHERE SPCONFIRM='        '  AND EXISTS (SELECT 1 FROM WASTGA B WHERE B.WAGGART=ABPART AND WAGGVAR=ABPVAR AND WAGGFARBE=ABPFARBE)";
                    break;
                case 3:
                    or1.CommandText = "UPDATE  ICC_MKRF SET JW='J ' WHERE SPCONFIRM='        '  AND  EXISTS (SELECT 1 FROM BASTGA B WHERE B.BAGGART=ABPART AND BAGGVAR=ABPVAR AND BAGGFARBE=ABPFARBE)";
                    break;
                case 4:
                    or1.CommandText = "UPDATE ICC_MKRF SET  MKFSMG1=(CASE WHEN ABFSOLLME=1 THEN ABFSOLLMG*0.1  ELSE 0 END), MKFSMG2=(CASE WHEN ABFSOLLME=2 THEN ABFSOLLMG*0.1  ELSE 0 END), MKFSMG3=(CASE WHEN ABFSOLLME=3 THEN ABFSOLLMG*0.1  ELSE 0 END), MKFSMG4=(CASE WHEN ABFSOLLME=4 THEN ABFSOLLMG*0.1  ELSE 0 END), MKFSMG5=(CASE WHEN ABFSOLLME=5 THEN ABFSOLLMG*0.1  ELSE 0 END), MKFSMG6=(CASE WHEN ABFSOLLME=6 THEN ABFSOLLMG*0.1  ELSE 0 END), MKFSMG7=(CASE WHEN ABFSOLLME=7 THEN ABFSOLLMG*0.1  ELSE 0 END), MKFSMG8=(CASE WHEN ABFSOLLME=8 THEN ABFSOLLMG*0.1  ELSE 0 END), MKFSME=ABFSOLLME  WHERE  SPCONFIRM='        ' AND JP50=0 AND MKFTP='0000'";
                    break;
                case 5:
                    or1.CommandText = "UPDATE ICC_MKRF SET (JP01,JP02,JP03,JP04,JP05)=(SELECT DISTINCT GSRECHNR*0.01*0.01,GSMAT,GSPROGRP,GSARTGRP,(MKFSMG1+MKFSMG2+MKFSMG3+MKFSMG4+MKFSMG5+MKFSMG6+MKFSMG7+MKFSMG8)*0.01 FROM GSDAT WHERE ABPART=GSART AND ABPVAR=GSVAR) WHERE SPCONFIRM='        '  AND JP50=0 AND EXISTS (SELECT 1 FROM GSDAT WHERE ABPART=GSART AND ABPVAR=GSVAR)";
                    
                    break;
                case 6:
                    or1.CommandText = "UPDATE ICC_MKRF SET (ABFMASCHZE,ABFMASCHZT,ABFBASMGE)=(SELECT DISTINCT 'ST',2400,NVL(MDAILY,100)*1000 FROM ICC_SPINSPEED WHERE JP01=YN) WHERE SPCONFIRM='        '  AND EXISTS (SELECT 1 FROM ICC_SPINSPEED WHERE JP01=YN)";
                    break;
                case 7:
                    //or1.CommandText = "UPDATE ICC_MKRF SET MACHINEID=(CASE WHEN RTRIM(JP06)='XS' THEN 'm99_9999_30' WHEN RTRIM(JP06)='HM' THEN 'm99_9999_20' WHEN RTRIM(JP06)='BX' THEN 'm99_9999_40' WHEN RTRIM(JP06)='MU' THEN 'm99_9999_10' ELSE 'm99_9999_10' END),JP07=(CASE WHEN RTRIM(JP06)='XS' THEN 'XSJobBar' WHEN RTRIM(JP06)='HM' THEN 'HMJobBar'  WHEN RTRIM(JP06)='BX' THEN 'BXJobBar'  WHEN RTRIM(JP06)='MU' THEN 'MUJobBar' ELSE 'JobBar' END)  WHERE ABFKST='9999' AND RTRIM(MACHINEID)=''";
                    break;
                case 8:
                    or1.CommandText = "UPDATE ICC_MKRF SET (JP11,JP12,JP13,JP14,JP15,JP16,JP17,JP18)=(SELECT ROUND(SUM(GAKG1)*0.01,0), ROUND(SUM(GAKG2)*0.01,0),  ROUND(SUM(GAKG3)*0.01,0),  ROUND(SUM(GAKG4)*0.01,0),   ROUND(SUM(GAKG5)*0.01,0),  ROUND(SUM(GAKG6)*0.01,0),  ROUND(SUM(GAKG7)*0.01,0),COUNT(*) FROM GAAUF WHERE GAAUFKRS=ABFAUFKRS AND GAAUFLFD=ABFAUFLFD AND GAAUFPOS=ABFAUFPOS AND GASA=:GASA GROUP BY GAAUFKRS,GAAUFLFD,GAAUFPOS) WHERE ABFKSTKRS='99' AND ABFKST='9999' AND MKFERLKZ=' ' AND  EXISTS (SELECT 1 FROM GAAUF WHERE GAAUFKRS=ABFAUFKRS AND GAAUFLFD=ABFAUFLFD AND GAAUFPOS=ABFAUFPOS AND GASA=:GASA )";
                    or1.Parameters.Add("GASA", OracleType.NVarChar).Value = dwData["C3"].ToString();
                    break;
                case 9:
                    or1.CommandText = "UPDATE ICC_MKRF SET (JP05,JP19,JP20,MKFPLDATV,MKFPLTIME,ENDATE,ENDTIME, ABFIENDDAT,ABFIENDZT,MKFERLKZ)=(SELECT  ROUND(ABPSOLLMENGE5*0.01,0), ABPEALFM*0.01, ROUND(ABPEAKG*0.01,0),ABPSTARTDAT,0,ABPENDDAT,0,ABPERLDAT,0,ABPERLKZ FROM ABPOS WHERE ABPAUFKRS=ABFAUFKRS AND ABPAUFLFD=ABFAUFLFD AND ABPAUFPOS=ABFAUFPOS) WHERE ABFKSTKRS='99' AND ABFKST='9999' AND MKFERLKZ=' ' AND  EXISTS (SELECT 1 FROM ABPOS WHERE ABPAUFKRS=ABFAUFKRS AND ABPAUFLFD=ABFAUFLFD AND ABPAUFPOS=ABFAUFPOS )";
                    break;
                case 10:
                    or1.CommandText = "UPDATE ICC_MKRF SET (JP21,JP22)=(SELECT   ROUND(SUM(ABARESMG)*0.001,0),COUNT(*) FROM ABAUFM WHERE ABAAUFKRS=ABFAUFKRS AND ABAAUFLFD=ABFAUFLFD AND ABAAUFPOS=ABFAUFPOS AND ABAVKAUFLFD<>'000000') WHERE ABFKSTKRS='99' AND ABFKST='9999' AND MKFERLKZ=' ' AND  EXISTS (SELECT 1 FROM ABAUFM WHERE ABAAUFKRS=ABFAUFKRS AND ABAAUFLFD=ABFAUFLFD AND ABAAUFPOS=ABFAUFPOS AND ABAVKAUFLFD<>'000000' )";
                    break;
                case 11:
                    or1.CommandText = "UPDATE ICC_MKRF X SET (ABFISTARTDAT,ABFISTARTZT)=(SELECT MIN(ABFISTARTDAT),0 FROM ABFOLGE F WHERE F.ABFAUFKRS=X.ABFAUFKRS AND F.ABFAUFLFD=X.ABFAUFLFD AND F.ABFAUFPOS=X.ABFAUFPOS) WHERE ABFKSTKRS='99' AND ABFKST='9999' AND MKFERLKZ=' ' AND  EXISTS (SELECT 1 FROM ABFOLGE F WHERE F.ABFAUFKRS=X.ABFAUFKRS AND F.ABFAUFLFD=X.ABFAUFLFD AND F.ABFAUFPOS=X.ABFAUFPOS )";
                    break;
                case 12:
                    or1.CommandText = "UPDATE ICC_MKRF SET (JP31,JP32,JP33,JP34,JP35,JP36,JP37)=(SELECT ROUND(SUM(BAMTR1)*0.01,0), ROUND(SUM(BAMTR2)*0.01,0),  ROUND(SUM(BAMTR3)*0.01,0),  ROUND(SUM(BAMTR4)*0.01,0),   ROUND(SUM(BAMTR5)*0.01,0),  ROUND(SUM(BAMTR6)*0.01,0),  ROUND(SUM(BAMTR7)*0.01,0) FROM BAAUF WHERE BAAUFKRS=ABFAUFKRS AND BAAUFLFD=ABFAUFLFD AND BAAUFPOS=ABFAUFPOS AND BASA=:BASA GROUP BY BAAUFKRS,BAAUFLFD,BAAUFPOS) WHERE ABFKSTKRS='99' AND ABFKST='9999' AND MKFERLKZ=' ' AND  EXISTS (SELECT 1 FROM BAAUF WHERE BAAUFKRS=ABFAUFKRS AND BAAUFLFD=ABFAUFLFD AND BAAUFPOS=ABFAUFPOS  AND BASA=:BASA )";
                    or1.Parameters.Add("BASA", OracleType.NVarChar).Value = dwData["C3"].ToString();
                    break;
                case 13:
                    or1.CommandText = "UPDATE ICC_MKRF SET (JP38,JP39,JP41)=(SELECT ROUND(SUM(WDBEDARF)*0.01,0), ROUND(SUM(WDZUGET)*0.01,0),  ROUND(SUM(WDRESERV)*0.01,0) FROM WDECK WHERE WDAUFKRS=ABFAUFKRS AND WDAUFLFD=ABFAUFLFD AND WDAUFPOS=ABFAUFPOS AND WDTYP=:WDTYP GROUP BY WDAUFKRS,WDAUFLFD,WDAUFPOS) WHERE ABFKSTKRS='99' AND ABFKST='9999' AND MKFERLKZ=' ' AND  EXISTS (SELECT 1 FROM WDECK WHERE WDTYP=:WDTYP AND WDAUFKRS=ABFAUFKRS AND WDAUFLFD=ABFAUFLFD AND WDAUFPOS=ABFAUFPOS )";
                    or1.Parameters.Add("WDTYP", OracleType.NVarChar).Value = dwData["WDTYP"].ToString();
                    break;

                //ABFSTATUS='R' 为完成的
            }
            Connect2Proxy(or1);
        }
        public DataSet DeleteICC_MKRF(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_MKRF WHERE  ABAID=:ABAID"; ;
                    or1.Parameters.Add("ABAID", OracleType.NVarChar).Value = dwData["ABAID"].ToString();
                    break;
                case 2:
                    or1.CommandText = "DELETE FROM ICC_MKRF WHERE  MKFERLKZ=:MKFERLKZ"; ;
                    or1.Parameters.Add("MKFERLKZ", OracleType.NVarChar).Value = dwData["MKFERLKZ"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
            return Result;
        }
    }
}
